/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialog_ChonThuMucDich.java
 *
 * Created on Jun 16, 2009, 1:57:53 AM
 */

package doanlythuyet_javaoutlook.MyUserControl;

import doanlythuyet_javaoutlook.DoAnLyThuyet_JavaOutLookApp;
import doanlythuyet_javaoutlook.EventListener_ClickChuotVaoCayDuyetFile;
import java.io.File;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class JDialog_ChonThuMucDich extends javax.swing.JDialog {

    private String m_ThuMucDuocChon = "";
    private JTreeFromXMLFile jTree_ThuMucMail;
    private JTreeFromXMLFile jTree_ThuMucNguoiDung;
    /** Creates new form JDialog_ChonThuMucDich */
    public JDialog_ChonThuMucDich(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        initMyComponent();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton_DongY = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane_ThuMucMail = new javax.swing.JScrollPane();
        jScrollPane_ThuMucNguoiDung = new javax.swing.JScrollPane();
        jLabel_DangChon = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(doanlythuyet_javaoutlook.DoAnLyThuyet_JavaOutLookApp.class).getContext().getResourceMap(JDialog_ChonThuMucDich.class);
        jButton_DongY.setText(resourceMap.getString("jButton_DongY.text")); // NOI18N
        jButton_DongY.setName("jButton_DongY"); // NOI18N
        jButton_DongY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_DongYActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane_ThuMucMail.setName("jScrollPane_ThuMucMail"); // NOI18N

        jScrollPane_ThuMucNguoiDung.setName("jScrollPane_ThuMucNguoiDung"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane_ThuMucMail, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane_ThuMucNguoiDung, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane_ThuMucNguoiDung, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                    .addComponent(jScrollPane_ThuMucMail, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
                .addContainerGap())
        );

        jLabel_DangChon.setText(resourceMap.getString("jLabel_DangChon.text")); // NOI18N
        jLabel_DangChon.setName("jLabel_DangChon"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel_DangChon)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 414, Short.MAX_VALUE)
                        .addComponent(jButton_DongY)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_DongY)
                    .addComponent(jLabel_DangChon))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public void initMyComponent (){
        String dataPath = DoAnLyThuyet_JavaOutLookApp.getCurdir() + "\\src";
        dataPath = new File(".").getAbsolutePath();
        String fileName = "\\Database\\XML_ThuMucMail.xml";
        //fileName =
        jTree_ThuMucMail = new JTreeFromXMLFile(dataPath + fileName, false);
        jScrollPane_ThuMucMail.setViewportView(jTree_ThuMucMail);
        jTree_ThuMucMail.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                jLabel_DangChon.setText(str_fileduocchon);
            }
        });


        //String dataPath = DoAnLyThuyet_JavaOutLookApp.getCurdir() + "\\src\\Database\\";

        fileName = "\\Database\\XML_ThuMucNguoiDung.xml";
        jTree_ThuMucNguoiDung = new JTreeFromXMLFile(dataPath + fileName, false);
        jScrollPane_ThuMucNguoiDung.setViewportView(jTree_ThuMucNguoiDung);
        jTree_ThuMucNguoiDung.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                jLabel_DangChon.setText(str_fileduocchon);
            }
        });
        //jTree_ThuMucMail.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

        //JTreeFromXMLFile tree = new JTreeFromXMLFile(xmlFilePath)
    }
    private void jButton_DongYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_DongYActionPerformed
        // TODO add your handling code here:
        m_ThuMucDuocChon = jLabel_DangChon.getText();
        if (m_ThuMucDuocChon.equals("")){
            JOptionPane.showMessageDialog(null, "Xin chọn thư mục!");
            return;
        }
        //this.getParent()
        setVisible(false);
    }//GEN-LAST:event_jButton_DongYActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JDialog_ChonThuMucDich dialog = new JDialog_ChonThuMucDich(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_DongY;
    private javax.swing.JLabel jLabel_DangChon;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane_ThuMucMail;
    private javax.swing.JScrollPane jScrollPane_ThuMucNguoiDung;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the m_ThuMucDuocChon
     */
    public String getM_ThuMucDuocChon() {
        return m_ThuMucDuocChon;
    }

}
